package com.niit.mall.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.mall.order.domain.dto.OrderItemDTO;
import com.niit.mall.order.domain.dto.OrderLogisticsDTO;
import com.niit.mall.order.domain.po.OrderItem;
import com.niit.mall.order.domain.po.OrderLogistics;
import com.niit.mall.order.mapper.OrderLogisticsMapper;
import com.niit.mall.order.service.IOrderLogisticsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @BelongsProject:pardo_mall_backendd
 * @BelongsPackage: com.niit.mall.order.service.impl
 * @Author: XihenXi
 * @CreateTime: 2025-06-17  16:52
 * @Description: TODO
 * @Version: 1.0
 */

@Service
public class OrderLogisticsServiceImpl extends ServiceImpl<OrderLogisticsMapper, OrderLogistics> implements IOrderLogisticsService {

    /**
     * 根据订单id查询物流信息
     * @param id 订单id
     * @return 物流信息
     */
    @Override
    public List<OrderLogisticsDTO> getByOrderId(Long id) {
        // 执行查询
        List<OrderLogistics> orderLogisticsList = lambdaQuery()
                .eq(OrderLogistics::getOrderId, id)
                .list();
        // 手动转换为 DTO 列表
        return orderLogisticsList.stream()
                .map(item -> {
                    OrderLogisticsDTO dto = new OrderLogisticsDTO();
                    dto.setId(item.getId());
                    dto.setOrderId(item.getOrderId());
                    dto.setLogisticsNumber(item.getLogisticsNumber());
                    dto.setLogisticsCompany(item.getLogisticsCompany());
                    dto.setContact(item.getContact());
                    dto.setPhone(item.getPhone());
                    dto.setAddressId(item.getAddressId());
                    dto.setCreateTime(item.getCreateTime());
                    dto.setUpdateTime(item.getUpdateTime());
                    return dto;
                })
                .collect(Collectors.toList());
    }
}
